import {createStore} from 'vuex'

let hasLogin = (uni.getStorageSync("userInfo") && uni.getStorageSync("userInfo").id) ? true : false;
let theme = uni.getStorageSync("theme") ? uni.getStorageSync("theme") : 'light';
let baseUrl = uni.getStorageSync("baseUrl") ? uni.getStorageSync("baseUrl") :"https://zhongkao.rongxinht.com";
console.log("111", hasLogin)

const store = createStore({
	state: {
		hasLogin: hasLogin,
		userInfo: uni.getStorageSync("userInfo") || {},
		baseUrl:baseUrl,
		apiPath:"/addons/shopro",
		currentCode:"1.0.0",
		useAddress:"",
		jiaonang:{}  //胶囊位置
	},
	getters: {
	  theme(state) {
	    return state[state.theme]
	  }
	},
	mutations: {
		//胶囊信息
		setJiaonang(state,item){
			state.jiaonang = item;
		},
		setUseAddress(state,item){
			state.useAddress = item;
		},
		clearLogin(state,item){
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({
				key: 'userInfo'
			})
		},
		login(state, provider) {
			console.log("change login")
			state.hasLogin = true;
			state.userInfo = provider;
			uni.setStorage({ //缓存用户登陆状态
				key: 'userInfo',
				data: provider
			})
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({
				key: 'userInfo'
			})
			uni.removeStorage({
				key: 'token'
			})
		},
	},
	actions: {

	},

})

export default store
